﻿// See https://aka.ms/new-console-template for more information



using Microsoft.Extensions.Caching.Memory;
using System;
MemoryCache _memoryCache = new MemoryCache(new MemoryCacheOptions());

var cacheKey = "HomeBanner";
if (!_memoryCache.TryGetValue(cacheKey, out var banners))
{
    banners = new List<string> { "banner1", "banner2", "banner3" };
    _memoryCache.Set(cacheKey, banners, TimeSpan.FromMinutes(1)); // 1分钟过期
}


var value1 = _memoryCache.Get(cacheKey) as List<string>;

value1.ToList();
var i = 0;


System.Threading.Thread.Sleep(60000);// 1分钟后

var value  =  _memoryCache.Get(cacheKey) as List<string>; 

foreach (var item in value)
{
    Console.WriteLine($"{i++} {item}");
}

Console.WriteLine("Hello, World!");
